/*
 *  $Id: SummonedObject.cs 944 2009-12-04 15:17:09Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;
using System.Collections.Generic;

using AgateLib.Geometry;

namespace Ragima {
    /// <summary>
    /// Абстрактный призванный объект
    /// Содержит: наложенные эффекты
    /// </summary>
    public abstract class SummonedObject: AbstractObject, ITabSource {
        private Player _owner, _summoner;
        protected bool _returnToHand;
        public readonly AffectIconItems AffectIcons;

        public SummonedObject(Player owner): base() {
            _owner = owner;
            _summoner = owner;
            _returnToHand = false;
            AffectIcons = new AffectIconItems(6);
        }

        /// <value>
        /// Игрок-владелец
        /// </value>
        public override Player Owner { get { return _owner; } }

        /// <value>
        /// Игрок-призыватель
        /// </value>
        public Player Summoner { get { return _summoner; } }

        /// <value>
        /// Карта, являющаяся данным призванным объектом
        /// </value>
        public abstract SummonableCard SummonCard { get; }

        public override Languages.Names Name {
            get { return SummonCard.Name; }
        }

        public override AffectSummary GlobalSummary {
            get { return _owner.GlobalSummary; }
        }

        /// <summary>
        /// Возврат карты в руки хозяина
        /// </summary>
        public virtual void ReturnToHand() {
            _returnToHand = true;
        }

        public abstract void Remove();

        public virtual void MoveCardAfterDeath() {
            Summoner.CardPutTo(SummonCard, _returnToHand ? CardPlace.Hands : SummonCard.PlaceAfterDeath);
        }

        public abstract void MoveToPlayer(Player newOwner);

        public void SetOwner(Player newOwner) {
            _owner = newOwner;
        }

        #region ITabSource methods
        public bool[] GetConditions(Player player) {
            bool[] result = new bool[2];
            result[0] = GetAbilities().Count > 0;
            result[1] = Summary.GetEnchantments().Count > 0;
            return result;
        }
        public IEnumerable<TabContent> GetTabs(Player player) {
            bool[] result = GetConditions(player);
            if (result[0]) yield return AbilitiesTabContent.GetContent(player.Tabs, player, this);
            if (result[1]) yield return EnchantmentsTabContent.GetContent(player.Tabs, this);
        }
        #endregion

        /// <summary>
        /// Событие после призыва
        /// </summary>
        public virtual void OnSummon() {}

        #region IHintable implementation
        public override Hint GetHint(Rectangle hintRect) {
            return SummonCard.GetHint(hintRect);
        }
        #endregion
   }
}